1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| #include<cstdio> #include<queue> #include<vector> #include<cstring> #include<algorithm> using namespace std; const int Max=21000000; typedef pair<int,int> Pair; priority_queue< Pair, vector<Pair>, greater<Pair> > Q; int dis[2100],head[2100]; int tail; struct data { int w,to,next; }edge[201000],k; void build(int a,int b,int x) { edge[tail].w=x; edge[tail].to=b; edge[tail].next=head[a]; head[a]=tail++; } void Dijkstra() { Pair s,u; int v,val; dis[0]=0; s.first=0; s.second=0; Q.push(s); while (!Q.empty()) { u=Q.top(); Q.pop(); val=u.first; v=u.second; if (dis[v]<val) continue; for (int i=head[v]; i!=-1; i=edge[i].next) { k=edge[i]; if (dis[k.to]>dis[v]+k.w) { dis[k.to]=dis[v]+k.w; Q.push(Pair(dis[k.to],k.to)); } } } } int main() { int T,S,D,a,b,x; while (scanf("%d%d%d",&T,&S,&D)!=EOF) { for (int i=0;i<2100;i++) head[i]=-1; for (int i=0;i<2100;i++) dis[i]=Max; tail=0; for (int i=1;i<=T;i++) { scanf("%d%d%d",&a,&b,&x); build(a,b,x); build(b,a,x); } for (int i=1;i<=S;i++) { scanf("%d",&x); build(0,x,0); build(x,0,0); } for (int i=1;i<=D;i++) { scanf("%d",&x); build(2000,x,0); build(x,2000,0); } Dijkstra(); printf("%d\n",dis[2000]); } return 0; }
|